let individualScores = [75,43,103,87,12]

var teamScore = 0

for score in individualScores{
	if score > 50 {
		teamScore += 3
	}else{
		teamScore+=1
	}
}

print("\(teamScore)")

var optionalString : String? //= "Hello"

print(optionalString == nil)

print("\(optionalString?.characters.count)")

var optionalName : String? = "John Apple"

var greeting = "Hello"

//let nameGreeting:String  = "shit" 


/*
 	在Swift中这里的optName必须为Optional类型的变量或常量。  if(name == optionalName)
 	右边是为nil的optional类型的值时，不会进行=号赋值，变量声明失败
*/
if let name = optionalName/**必须是Optional类型*/{
	greeting = "Hello \(name)"
} 

print("\(greeting)")



let nickName:String? = nil

let fullName:String = "John Apple seed"

let informalGreeting = "Hi \(nickName ?? fullName)" //如果nickName 是 nil 取默认值  such as:    ?:

print("\(informalGreeting)")



//开关语句

let vegetable =  "pepper"

switch vegetable{
	case "celery":
		print("celery")
		
	case "pepper":
		print("pepper")
		
	case "cucumber","watercress":
		print("cucumber or watercress")
		
	case let x where x.hasSuffix("pepper")://where 是 swift 语言的条件判断关键字
		print("it should be some kind of peppers")
		
	default://必须声明默认
		print("not kind of vegetalbes")
		
}//result is pepper

//if let p where p.hasSuffix("er"){
//	print("p has a suffix of er")
//}

let interestingNumbers = [
	"Prime":[2,3,5,7,11,13],
	"Finonacci":[1,1,2,3,5,8],
	"Square":[1,4,9,16,25,36],
]

var largest = 0

for(kind,numbers) in interestingNumbers{
	for number in numbers {
		if number > largest{
			largest = number
		}
	}
}

print("largest number is \(largest)")

var n = 2 

while n < 100{
	n = n * 2
}

print("n = "+String(n))

var m = 2 
repeat{
	m = m * 2
}while m < 100

print("m = "+String(m))

var toal = 0

for i in 0..<4{
	toal += i
}

print("total is " + String(toal))


var arayOfFabonica = interestingNumbers["Finonacci"]

var count:Int = arayOfFabonica!.count as Int 
print("count is "+String(count))

var sumOfFabocci:Int = 0

for i in 0..<count{
	sumOfFabocci += arayOfFabonica![i]
}

print("arayOfFabonica sum is " + String(sumOfFabocci))//1+1+2+3+5+8






















